package com.banshuibao.bsb_android.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.model.MediaModel;
import com.banshuibao.bsb_android.util.ImageUtil;

/**
 * Created by zyh on 2017/12/21.
 */

public class InterViewGrideListAdapter extends MyBaseAdapter<MediaModel.Data> {

    public InterViewGrideListAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MediaViewHolder holder;
        if (view == null) {
            holder = new MediaViewHolder();
            view = layoutInflater.inflate(R.layout.gridview_item_layout, viewGroup, false);
            holder.ad_iv = view.findViewById(R.id.img2);
            holder.title = view.findViewById(R.id.text2);
            holder.price = view.findViewById(R.id.price2);
            holder.price_tag = view.findViewById(R.id.price_icon2);
            view.setTag(holder);
        } else
            holder = (MediaViewHolder) view.getTag();
        MediaModel.Data data = getItem(i);
        if (data != null) {
            holder.title.setText(data.getTitle());
            holder.title.setSelected(true);
           /* if (data.getPrice() == 0) {*/
            holder.price.setVisibility(View.GONE);
            holder.price_tag.setVisibility(View.GONE);
          /*  } else {
              //  holder.price.setText(PriceUtil.FormatPrice(data.getPrice()));//保留两位小数格式
                holder.price.setVisibility(View.VISIBLE);
                holder.price_tag.setVisibility(View.VISIBLE);
                holder.price.setText(String.valueOf(data.getPrice()));
            }*/
            ImageUtil.loadImage(context, data.getImage(), holder.ad_iv);
        }
        return view;
    }

    private class MediaViewHolder {
        ImageView ad_iv;
        TextView title, price, price_tag;
    }
}
